# -*- coding: utf-8 -*-
# @Time : 2021/2/3 上午 12:24
# @Author : lijunlong
# @Email : 729619494@qq.com
# @File : test_clientsearch_ture.py
# @Project : test0
import tools.globalvar as gl

class BasePage():

    """
    定义基础页面属性和方法
    """
    url_ = ""  #默认一个url
    def __init__(self,driver,url=None):
        try:
            if url:
                self.url = url
            else:
                self.url = self.url_
        except Exception:
            raise NameError("BasePage的子类没有url_属性")
        self.driver = driver
        self.timeout = 30

    def open(self):  # 打开浏览器
        self.driver.get(self.url)
        self.driver.implicitly_wait(self.timeout)  # 设置隐式等待

    def get_current_url(self):  # 获取当前url
        return self.driver.current_url

    def findE(self,locator):  # 查找元素简化
        return self.driver.find_element(*locator)

    def findEs(self,locator):  # 查找元素简化
        return self.driver.find_elements(*locator)

    def get_alert_text(self): # 获取警告弹窗文本
        return self.driver.switch_to.alert.text

    def accept_alert(self):  # 接受警告弹窗
        return self.driver.switch_to.alert.accept()

    def find_element(self, locator):
        return self.driver.find_element(*locator)
    def use_cookies(self,page): # 任意跳转页面
        """
        page：页面的类名称，如:ClientPage
        """
        self.driver.get("http://192.168.1.14/")
        self.driver.add_cookie({'domain': '192.168.1.14', 'httpOnly': False, 'name': 'PHPSESSID', 'path': '/crm', 'secure': False, 'value': '6crli4a0n6oqm31harmn9ehui7'})
        self.driver.get(page.url_)

